package com.ict.web.dto;

import com.ict.common.annotation.Excel;
import com.ict.common.utils.StringUtils;
import com.ict.common.utils.bean.BeanUtils;
import com.ict.common.utils.uuid.IdUtils;
import com.ict.web.controller.file.domain.YzqFile;
import com.ict.web.controller.file.dto.YzqFileDTO;
import com.ict.web.domain.SchemeDeclaration;
import com.ict.web.domain.SystemInfo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.Digits;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Data
public class SchemeDeclarationAddDto {
    /** 设计单位 */
    @ApiModelProperty(value = "设计单位")
    @NotBlank(message = "设计单位不能为空")
    private String designUnit;

    /** 可行性研究报告 */
    @ApiModelProperty(value = "可行性研究报告")
//    @NotNull(message = "可行性研究报告不能为空")
    private YzqFileDTO researchReport;

    /** 概算方案 */
    @ApiModelProperty(value = "概算方案")
//    @NotNull(message = "概算方案不能为空")
    private YzqFileDTO budgetProposal;

    /** 初设方案 */
    @ApiModelProperty(value = "初设方案")
//    @NotNull(message = "初设方案不能为空")
    private YzqFileDTO preliminaryDesignScheme;

    /** 预算方案 */
    @ApiModelProperty(value = "预算方案")
//    @NotNull(message = "预算方案不能为空")
    private YzqFileDTO budgetProgramme;

    /** 云资源需求申请表 */
    @ApiModelProperty(value = "云资源需求申请表")
    private YzqFileDTO cloudResourceApplication;

    /** 系统架构简述 */
    @Excel(name = "系统架构简述")
    @ApiModelProperty(value = "系统架构简述")
    @NotNull(message = "系统架构简述不能为空")
    private String systemArchitecture;

    /** 项目id */
    @ApiModelProperty(value = "项目id")
    private Long proId;

    @ApiModelProperty(value = "系统信息列表")
    private List<SystemInfo> systemInfoList;

    @ApiModelProperty(value = "政务数据资源目录清单")
    private List<GovernmentDataResourceAddDto> governmentDataResourcesAddDtoList;

    @ApiModelProperty(value = "云资源需求列表")
    private List<InsertCloudResourceDto> insertCloudResourceDtoList;

    @ApiModelProperty(value = "物联设备信息")
    private List<InsertIotDeviceInfoDto> insertIotDeviceInfoDtosList;

    /** 项目投资估算（万元） */
    @ApiModelProperty(value = "项目投资估算")
    @NotNull(message = "项目投资估算不能为空")
    @Digits(integer=14,fraction = 6,message = "整数位上限为14位，小数位上限为6位")
    private BigDecimal projectInvestmentEstimation;

    /** 评估方法 */
    @ApiModelProperty(value = "评估方法")
    @NotBlank(message = "评估方法不能为空")
    private String assessmentMethod;

    /** 项目代码 */
    @ApiModelProperty(value = "项目代码")
    @Size(max = 32, message = "项目代码长度不能超过32")
    private String projectCode;
    /**
     * 将 AnnualProjectPlanAddDto 转化为 AnnualProjectPlan
     *
     * @param dto 接收dto
     * @return HotelInfo
     */
    public static SchemeDeclaration of(SchemeDeclarationAddDto dto){
        SchemeDeclaration bean = new SchemeDeclaration();
        BeanUtils.copyProperties(dto,bean);

        //设置ID
        bean.setProgrammeId(IdUtils.snowId());
        //设置创建时间
        bean.setCreateTime(LocalDateTime.now());
        //设置创建时间
        bean.setUpdateTime(LocalDateTime.now());
        //设置物理删除标记
        bean.setDelFlag("0");

        return bean;
    }
    /**
     * 将 AnnualProjectPlanAddDto中需传文件对象 转化为 file
     *
     * @param dto 接收dto
     * @return HotelInfo
     */
    public static ArrayList<YzqFile> toFile(SchemeDeclaration schemeDeclaration, SchemeDeclarationAddDto dto){
        ArrayList<YzqFile> fileList = new ArrayList<>();
        if (dto.getResearchReport()!=null&&StringUtils.isNotEmpty(dto.getResearchReport().getFileName())){
                YzqFileDTO Rr = dto.getResearchReport();
                YzqFile fileRr = new YzqFile();
                fileRr.setId(String.valueOf(IdUtils.snowId()));
                BeanUtils.copyProperties(Rr,fileRr);
                fileList.add(fileRr);
                schemeDeclaration.setResearchReport(fileRr.getId());
        }

        if (dto.getBudgetProposal()!=null&&StringUtils.isNotEmpty(dto.getBudgetProposal().getFileName())) {
                YzqFileDTO Bp = dto.getBudgetProposal();
                YzqFile fileBp = new YzqFile();
                fileBp.setId(String.valueOf(IdUtils.snowId()));
                BeanUtils.copyProperties(Bp,fileBp);
                fileList.add(fileBp);
                schemeDeclaration.setBudgetProposal(fileBp.getId());

        }

        if (dto.getPreliminaryDesignScheme()!=null&&StringUtils.isNotEmpty(dto.getPreliminaryDesignScheme().getFileName())) {
                YzqFileDTO Pd = dto.getPreliminaryDesignScheme();
                YzqFile filePd = new YzqFile();
                filePd.setId(String.valueOf(IdUtils.snowId()));
                BeanUtils.copyProperties(Pd,filePd);
                filePd.setRelationId(String.valueOf(dto.getProId()));
                fileList.add(filePd);
                schemeDeclaration.setPreliminaryDesignScheme(filePd.getId());


        }

        if (dto.getBudgetProgramme()!=null&&StringUtils.isNotEmpty(dto.getBudgetProgramme().getFileName())) {
                YzqFileDTO Bpm = dto.getBudgetProgramme();
                YzqFile fileBpm = new YzqFile();
                fileBpm.setId(String.valueOf(IdUtils.snowId()));
                BeanUtils.copyProperties(Bpm,fileBpm);
                fileList.add(fileBpm);
                schemeDeclaration.setBudgetProgramme(fileBpm.getId());
        }

        if (dto.getCloudResourceApplication()!=null&&StringUtils.isNotEmpty(dto.getCloudResourceApplication().getFileName())) {
                YzqFileDTO Ca = dto.getCloudResourceApplication();
                YzqFile fileCa = new YzqFile();
                fileCa.setId(String.valueOf(IdUtils.snowId()));
                BeanUtils.copyProperties(Ca,fileCa);
                fileList.add(fileCa);
                schemeDeclaration.setCloudResourceApplication(fileCa.getId());
        }

        return fileList;
    }
}
